package net.flowas.genericcrud.audit.model;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.PrePersist;

/**
 * 用户行为统计数据。
 * 
 * @author liujh
 *
 */
@Entity
@IdClass(AuditValuePK.class)
public class AuditValue implements Serializable{
	/**
	 * 模型类型,如Product等
	 */
	@Id
	private String modelType;
	/**
	 * 审计对象的标识
	 */
	@Id
	private Long auditFor;
	/**
	 * 浏览次数
	 */
	private Long browseNum;
	/**
	 * 关注数量
	 */
	private Long followNum;
	/**
	 * 点赞数量
	 */
	private Long likeNum;
	/**
	 * 评论数量
	 */
	private Long commentNum;

	public Long getBrowseNum() {
		return browseNum;
	}

	public void setBrowseNum(Long browseNum) {
		this.browseNum = browseNum;
	}

	public Long getFollowNum() {
		return followNum;
	}

	public void setFollowNum(Long followNum) {
		this.followNum = followNum;
	}

	public Long getLikeNum() {
		return likeNum;
	}

	public void setLikeNum(Long likeNum) {
		this.likeNum = likeNum;
	}

	public Long getCommentNum() {
		return commentNum;
	}

	public void setCommentNum(Long commentNum) {
		this.commentNum = commentNum;
	}

	public String getModelType() {
		return modelType;
	}

	public void setModelType(String modelType) {
		this.modelType = modelType;
	}

	public Long getAuditFor() {
		return auditFor;
	}

	public void setAuditFor(Long auditFor) {
		this.auditFor = auditFor;
	}

	@PrePersist
	void preInsert() {
		if (browseNum == null) {
			browseNum = 0L;
		}
		if (followNum == null) {
			followNum = 0L;
		}
		if (likeNum == null) {
			likeNum = 0L;
		}
		if (commentNum == null) {
			commentNum = 0L;
		}
	}
}
